<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-comment">{- |
   Module      :  System.Win32.Encoding
   Copyright   :  2012 shelarcy
   License     :  BSD-style

   Maintainer  :  shelarcy@gmail.com
   Stability   :  Provisional
   Portability :  Non-portable (Win32 API)

   Enocode/Decode mutibyte charactor using Win32 API.
-}</span><span>
</span><span id="line-13"></span><span>
</span><span id="line-14"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Win32.Encoding</span><span>
</span><span id="line-15"></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#getCurrentCodePage"><span class="hs-identifier">getCurrentCodePage</span></a></span><span>
</span><span id="line-16"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#encodeMultiByte"><span class="hs-identifier">encodeMultiByte</span></a></span><span>
</span><span id="line-17"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#encodeMultiByteIO"><span class="hs-identifier">encodeMultiByteIO</span></a></span><span>
</span><span id="line-18"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#decodeMultiByte"><span class="hs-identifier">decodeMultiByte</span></a></span><span>
</span><span id="line-19"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#decodeMultiByteIO"><span class="hs-identifier">decodeMultiByteIO</span></a></span><span>
</span><span id="line-20"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#wideCharToMultiByte"><span class="hs-identifier">wideCharToMultiByte</span></a></span><span>
</span><span id="line-21"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Win32.NLS.html#multiByteToWideChar"><span class="hs-identifier">multiByteToWideChar</span></a></span><span>
</span><span id="line-22"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CInt"><span class="hs-identifier">CInt</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#"><span class="hs-identifier">Foreign.C.String</span></a></span><span>       </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.C.String.html#peekCAStringLen"><span class="hs-identifier">peekCAStringLen</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.String.html#withCWStringLen"><span class="hs-identifier">withCWStringLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Marshal.Array.html#"><span class="hs-identifier">Foreign.Marshal.Array</span></a></span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.Marshal.Array.html#allocaArray"><span class="hs-identifier">allocaArray</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Marshal.Unsafe.html#"><span class="hs-identifier">Foreign.Marshal.Unsafe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.Marshal.Unsafe.html#unsafeLocalState"><span class="hs-identifier">unsafeLocalState</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.Console.html"><span class="hs-identifier">System.Win32.Console</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.NLS.html"><span class="hs-identifier">System.Win32.NLS</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Win32.Types.html"><span class="hs-identifier">System.Win32.Types</span></a></span><span class="hs-cpp">

#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- note CodePage = UInt which might not work on Win64.  But the Win32 package</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- also has this issue.</span><span>
</span><span id="line-36"></span><span class="annot"><a href="System.Win32.Encoding.html#getCurrentCodePage"><span class="hs-identifier hs-type">getCurrentCodePage</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="System.Win32.Types.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>
</span><span id="line-37"></span><span id="getCurrentCodePage"><span class="annot"><span class="annottext">getCurrentCodePage :: IO DWORD
</span><a href="System.Win32.Encoding.html#getCurrentCodePage"><span class="hs-identifier hs-var hs-var">getCurrentCodePage</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-38"></span><span>    </span><span id="local-6989586621679116624"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116624"><span class="hs-identifier hs-var">conCP</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Win32.Console.html#getConsoleCP"><span class="hs-identifier hs-var">getConsoleCP</span></a></span><span>
</span><span id="line-39"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116624"><span class="hs-identifier hs-var">conCP</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span>
</span><span id="line-40"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; IO DWORD
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116624"><span class="hs-identifier hs-var">conCP</span></a></span><span>
</span><span id="line-41"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Win32.NLS.html#getACP"><span class="hs-identifier hs-var">getACP</span></a></span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- | The &quot;System.IO&quot; output functions (e.g. `putStr`) don't</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- automatically convert to multibyte string on Windows, so this</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- function is provided to make the conversion from a Unicode string</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- in the given code page to a proper multibyte string.  To get the</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- code page for the console, use `getCurrentCodePage`.</span><span>
</span><span id="line-48"></span><span class="hs-comment">--</span><span>
</span><span id="line-49"></span><span class="annot"><a href="System.Win32.Encoding.html#encodeMultiByte"><span class="hs-identifier hs-type">encodeMultiByte</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Encoding.CodePage.html#CodePage"><span class="hs-identifier hs-type">CodePage</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-50"></span><span id="encodeMultiByte"><span class="annot"><span class="annottext">encodeMultiByte :: DWORD -&gt; String -&gt; String
</span><a href="System.Win32.Encoding.html#encodeMultiByte"><span class="hs-identifier hs-var hs-var">encodeMultiByte</span></a></span></span><span> </span><span id="local-6989586621679116619"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116619"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; String
forall a. IO a -&gt; a
</span><a href="../../base/src/Foreign.Marshal.Unsafe.html#unsafeLocalState"><span class="hs-identifier hs-var">unsafeLocalState</span></a></span><span> </span><span class="annot"><span class="annottext">(IO String -&gt; String) -&gt; (String -&gt; IO String) -&gt; String -&gt; String
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; String -&gt; IO String
</span><a href="System.Win32.Encoding.html#encodeMultiByteIO"><span class="hs-identifier hs-var">encodeMultiByteIO</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116619"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="annot"><a href="System.Win32.Encoding.html#encodeMultiByteIO"><span class="hs-identifier hs-type">encodeMultiByteIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Encoding.CodePage.html#CodePage"><span class="hs-identifier hs-type">CodePage</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-53"></span><span id="encodeMultiByteIO"><span class="annot"><span class="annottext">encodeMultiByteIO :: DWORD -&gt; String -&gt; IO String
</span><a href="System.Win32.Encoding.html#encodeMultiByteIO"><span class="hs-identifier hs-var hs-var">encodeMultiByteIO</span></a></span></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-54"></span><span>  </span><span class="hs-comment">-- WideCharToMultiByte doesn't handle empty strings</span><span>
</span><span id="line-55"></span><span class="annot"><a href="System.Win32.Encoding.html#encodeMultiByteIO"><span class="hs-identifier hs-var">encodeMultiByteIO</span></a></span><span> </span><span id="local-6989586621679116617"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116617"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span id="local-6989586621679116616"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679116616"><span class="hs-identifier hs-var">wstr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-56"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; (CWStringLen -&gt; IO String) -&gt; IO String
forall a. String -&gt; (CWStringLen -&gt; IO a) -&gt; IO a
</span><a href="../../base/src/Foreign.C.String.html#withCWStringLen"><span class="hs-identifier hs-var">withCWStringLen</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679116616"><span class="hs-identifier hs-var">wstr</span></a></span><span> </span><span class="annot"><span class="annottext">((CWStringLen -&gt; IO String) -&gt; IO String)
-&gt; (CWStringLen -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679116615"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679116615"><span class="hs-identifier hs-var">cwstr</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679116614"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679116614"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-57"></span><span>    </span><span id="local-6989586621679116613"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679116613"><span class="hs-identifier hs-var">mbchars'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO CInt -&gt; IO CInt
forall a. (Eq a, Num a) =&gt; String -&gt; IO a -&gt; IO a
</span><a href="System.Win32.Types.html#failIfZero"><span class="hs-identifier hs-var">failIfZero</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;WideCharToMultiByte&quot;</span></span><span> </span><span class="annot"><span class="annottext">(IO CInt -&gt; IO CInt) -&gt; IO CInt -&gt; IO CInt
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
-&gt; DWORD
-&gt; Ptr CWchar
-&gt; CInt
-&gt; LPSTR
-&gt; CInt
-&gt; LPSTR
-&gt; LPBOOL
-&gt; IO CInt
</span><a href="System.Win32.Encoding.html#wideCharToMultiByte"><span class="hs-identifier hs-var">wideCharToMultiByte</span></a></span><span> </span><span>
</span><span id="line-58"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116617"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-59"></span><span>                </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span>
</span><span id="line-60"></span><span>                </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679116615"><span class="hs-identifier hs-var">cwstr</span></a></span><span>
</span><span id="line-61"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679116614"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span>                </span><span class="annot"><span class="annottext">LPSTR
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span>
</span><span id="line-63"></span><span>                </span><span class="annot"><span class="annottext">LPSTR
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="annot"><span class="annottext">LPBOOL
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-64"></span><span>    </span><span class="hs-comment">-- mbchar' is the length of buffer required</span><span>
</span><span id="line-65"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; (LPSTR -&gt; IO String) -&gt; IO String
forall a b. Storable a =&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/Foreign.Marshal.Array.html#allocaArray"><span class="hs-identifier hs-var">allocaArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CInt -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679116613"><span class="hs-identifier hs-var">mbchars'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((LPSTR -&gt; IO String) -&gt; IO String)
-&gt; (LPSTR -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679116610"><span class="annot"><span class="annottext">LPSTR
</span><a href="#local-6989586621679116610"><span class="hs-identifier hs-var">mbstr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-66"></span><span>      </span><span id="local-6989586621679116609"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679116609"><span class="hs-identifier hs-var">mbchars</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO CInt -&gt; IO CInt
forall a. (Eq a, Num a) =&gt; String -&gt; IO a -&gt; IO a
</span><a href="System.Win32.Types.html#failIfZero"><span class="hs-identifier hs-var">failIfZero</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;WideCharToMultiByte&quot;</span></span><span> </span><span class="annot"><span class="annottext">(IO CInt -&gt; IO CInt) -&gt; IO CInt -&gt; IO CInt
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
-&gt; DWORD
-&gt; Ptr CWchar
-&gt; CInt
-&gt; LPSTR
-&gt; CInt
-&gt; LPSTR
-&gt; LPBOOL
-&gt; IO CInt
</span><a href="System.Win32.Encoding.html#wideCharToMultiByte"><span class="hs-identifier hs-var">wideCharToMultiByte</span></a></span><span> </span><span>
</span><span id="line-67"></span><span>                 </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116617"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-68"></span><span>                 </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span>
</span><span id="line-69"></span><span>                 </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679116615"><span class="hs-identifier hs-var">cwstr</span></a></span><span>
</span><span id="line-70"></span><span>                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679116614"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-71"></span><span>                 </span><span class="annot"><span class="annottext">LPSTR
</span><a href="#local-6989586621679116610"><span class="hs-identifier hs-var">mbstr</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679116613"><span class="hs-identifier hs-var">mbchars'</span></a></span><span>
</span><span id="line-72"></span><span>                 </span><span class="annot"><span class="annottext">LPSTR
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="annot"><span class="annottext">LPBOOL
forall a. Ptr a
</span><a href="../../base/src/GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-73"></span><span>      </span><span class="annot"><span class="annottext">CStringLen -&gt; IO String
</span><a href="../../base/src/Foreign.C.String.html#peekCAStringLen"><span class="hs-identifier hs-var">peekCAStringLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LPSTR
</span><a href="#local-6989586621679116610"><span class="hs-identifier hs-var">mbstr</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CInt -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679116609"><span class="hs-identifier hs-var">mbchars</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- converts [Char] to UTF-16</span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;WideCharToMultiByte&quot;</span><span>
</span><span id="line-76"></span><span>  </span><span id="wideCharToMultiByte"><span class="annot"><a href="System.Win32.Encoding.html#wideCharToMultiByte"><span class="hs-identifier hs-var">wideCharToMultiByte</span></a></span></span><span>
</span><span id="line-77"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Encoding.CodePage.html#CodePage"><span class="hs-identifier hs-type">CodePage</span></a></span><span>
</span><span id="line-78"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Win32.Types.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>   </span><span class="hs-comment">-- dwFlags,</span><span>
</span><span id="line-79"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Win32.Types.html#LPCWSTR"><span class="hs-identifier hs-type">LPCWSTR</span></a></span><span> </span><span class="hs-comment">-- lpWideCharStr</span><span>
</span><span id="line-80"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>    </span><span class="hs-comment">-- cchWideChar</span><span>
</span><span id="line-81"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Win32.Types.html#LPSTR"><span class="hs-identifier hs-type">LPSTR</span></a></span><span>   </span><span class="hs-comment">-- lpMultiByteStr</span><span>
</span><span id="line-82"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>    </span><span class="hs-comment">-- cbMultiByte</span><span>
</span><span id="line-83"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Win32.Types.html#LPCSTR"><span class="hs-identifier hs-type">LPCSTR</span></a></span><span>  </span><span class="hs-comment">-- lpMultiByteStr</span><span>
</span><span id="line-84"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Win32.Types.html#LPBOOL"><span class="hs-identifier hs-type">LPBOOL</span></a></span><span>  </span><span class="hs-comment">-- lpbFlags</span><span>
</span><span id="line-85"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-86"></span><span>
</span><span id="line-87"></span><span class="hs-comment">-- | The &quot;System.IO&quot; input functions (e.g. `getLine`) don't</span><span>
</span><span id="line-88"></span><span class="hs-comment">-- automatically convert to Unicode, so this function is provided to</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- make the conversion from a multibyte string in the given code page </span><span>
</span><span id="line-90"></span><span class="hs-comment">-- to a proper Unicode string.  To get the code page for the console,</span><span>
</span><span id="line-91"></span><span class="hs-comment">-- use `getCurrentCodePage`.</span><span>
</span><span id="line-92"></span><span class="annot"><a href="System.Win32.Encoding.html#decodeMultiByte"><span class="hs-identifier hs-type">decodeMultiByte</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Encoding.CodePage.html#CodePage"><span class="hs-identifier hs-type">CodePage</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-93"></span><span id="decodeMultiByte"><span class="annot"><span class="annottext">decodeMultiByte :: DWORD -&gt; String -&gt; String
</span><a href="System.Win32.Encoding.html#decodeMultiByte"><span class="hs-identifier hs-var hs-var">decodeMultiByte</span></a></span></span><span> </span><span id="local-6989586621679116606"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116606"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; String
forall a. IO a -&gt; a
</span><a href="../../base/src/Foreign.Marshal.Unsafe.html#unsafeLocalState"><span class="hs-identifier hs-var">unsafeLocalState</span></a></span><span> </span><span class="annot"><span class="annottext">(IO String -&gt; String) -&gt; (String -&gt; IO String) -&gt; String -&gt; String
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; String -&gt; IO String
</span><a href="System.Win32.Encoding.html#decodeMultiByteIO"><span class="hs-identifier hs-var">decodeMultiByteIO</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679116606"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-94"></span><span>
</span><span id="line-95"></span><span class="hs-comment">-- | Because of `stringToUnicode` is unclear name, we use `decodeMultiByteIO`</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- for alias of `stringToUnicode`. </span><span>
</span><span id="line-97"></span><span class="annot"><a href="System.Win32.Encoding.html#decodeMultiByteIO"><span class="hs-identifier hs-type">decodeMultiByteIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Encoding.CodePage.html#CodePage"><span class="hs-identifier hs-type">CodePage</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-98"></span><span id="decodeMultiByteIO"><span class="annot"><span class="annottext">decodeMultiByteIO :: DWORD -&gt; String -&gt; IO String
</span><a href="System.Win32.Encoding.html#decodeMultiByteIO"><span class="hs-identifier hs-var hs-var">decodeMultiByteIO</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; String -&gt; IO String
</span><a href="System.Win32.NLS.html#stringToUnicode"><span class="hs-identifier hs-var">stringToUnicode</span></a></span><span>
</span><span id="line-99"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="System.Win32.Encoding.html#decodeMultiByteIO"><span class="hs-pragma hs-type">decodeMultiByteIO</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-100"></span></pre></body></html>